<template>
    <div class=" index-page">

        <!-- <div class="student">
            <el-input placeholder="请选择学生" icon="search" v-model="student" class="input" @focus="componentsShow('student')"></el-input>
            <el-button type="text">缴费记录</el-button>
        </div> -->

        <!-- <div class="btn">

        </div> -->
        <div class="but1">
        <i class="el-icon-close close-top" @click="cancel"></i>
        <router-link to="/home">
			<el-button type="warning" class="add btn" style='margin-left: 5px;margin-right: 0px;' icon="el-icon-menu">首页</el-button>
		</router-link>
		<el-button type="success" class="add btn" style='margin-left: 8px;margin-right:8px;'   @click="cancel" icon="el-icon-caret-left" >返回</el-button>
		 <span>学生：</span>
            <el-input  v-model="name" :readonly="true" class="code-search"></el-input>
        
        
        <!-- <el-button type="primary" class="add btn" @click="componentsShow('course')">购买课时</el-button>
        <el-button type="primary" class="add btn" @click="componentsShow('xzwp')">购买物品</el-button> -->

        </div>
            <el-table
                :data="dataList"
                :v-loading="false"
                element-loading-text="拼命加载中"
                border
                stripe
                size="mini"
                align="center"
                class="admin-table"
                :row-class-name="tableRowClassName">
                <el-table-column
                    :prop="v.prop"
                    :label="v.label"
                    v-for="(v,index) in portTitleList"
                    align="center"
                    show-overflow-tooltip
                    v-if="v.hide != 0"
                    :formatter="v.formatter"
                    :align="v.align || 'center'"
                    :fixed="v.fixed"
                    :class-name="v.columnStyle"
                    :width="v.width"
                    :min-width="v.minWidth"
                    :header-align="v.headerAlign || 'center'"
                    >
                </el-table-column>
            </el-table>
        </el-table>

        <div class="total">
            <span>课程：￥{{courseTotal}}</span>
            <span>物品：￥{{goodsTotal}}</span>
            <span>合计：￥{{totalAmount}}</span>
        </div>
        <article class="settlement">
            <p>上次结算</p>
            <div>
                直减优惠：<input type="text" v-model="yzj" disabled> 
                代金券抵扣：<input type="text" v-model="yyhj" disabled> 
                已收金额：<input type="text" v-model="amountReceived" disabled> 
                需交金额：<input type="text" v-model="xujiao" disabled>
            </div>
        </article>
       
        <article class="receiving-account">
            <p>本次结算</p>
            <div>
                直减优惠：<input type="text" v-model="zj" >
                代金券抵扣：<input type="text" v-model="yhj" >
                余额支付：<input style="width:100px;"  type="text" v-model="zfyuer" >（可用余额 {{sjyuer}}）
            </div>
        </article>
         <div class="total">
            <span>应交金额：￥{{yjje1}}</span>
            <span>实交金额：￥{{sum}}</span>
            <span>本次预存：￥{{yucun}}</span>
        </div>

        <article class="receiving-account">
            <p>收款账户</p>
            <div>
                现金：<input type="text" v-model="money.xj">
                还需交：（￥<span style="color:red;">{{qf1}}</span>）
                <span class="space-between"></span>
                支付宝账号：<input type="text" v-model="money.zfbzh">
                金额：<input type="text" v-model="money.zfbzhje">
                <span class="space-between"></span>
                微信账号：<input type="text" v-model="money.wxzh">
                金额：<input type="text" v-model="money.wxzhje">
                <span class="space-between"></span>
                银行卡账号：<input type="text" v-model="money.yhzh">
                金额：<input type="text" v-model="money.yhzhje">
                <!-- <span class="space-between"></span>
                总续费金额：<input type="text" v-model="xfje"> -->
            </div>
        </article>

        <!-- <article class="other-information">
            <p>其他信息</p>
            <div>
                购买日期：<el-date-picker type="date" placeholder="请选择日期" v-model="date" class="item-input" @change="getTime"></el-date-picker>
            </div>
        </article> -->
        <el-button type="primary" class="submit" @click="submit">补交</el-button>
        <el-button  type="danger" class="submit2"  @click="zuofei">作废</el-button>
        <el-button type="danger" class="submit3" v-if="info.islq=='未领取' && info.button=='Y' "  @click="componentsShow('ly')">领取</el-button>
		<el-button type="danger"class="submit3" v-if="info.islq=='已领取'" disabled >已领取</el-button>


        <!-- 各个组件显示区域 -->

        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
		<LyComponent v-if="portComponents.ly.toggle" @close="componentsHide" :params="this.params"></LyComponent>
        <PayCourse v-if="portComponents.course.toggle"  @close="componentsHide"  :data="portComponents.course.data"></PayCourse>
        <Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data"></Xzwplist>

        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>

<script>


    import qs from 'qs'
    import Vue from 'vue'
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    import PayCourse from '../pay/pay-course'
    import Xzwplist from '../../manage/bs/xzwp'
	import LyComponent from './ly'
    export default {
        props: ['params'],
        components: {
            LoadingComponent,
            PayCourse,
            LyComponent,
            Xzwplist
        },
        data () {
            return {
            	info:{
            	isqy:'',
            	},
              yzj:'',
              zj:0,
              yhj:0,
              yyhj:'',
                name: '',
                student: '',
                studentList: [],
                addlist:[],
                date: '',
                oldTicket: 0,
                ticket: 10,
                amountReceived: 0,
                needPay: 10,
                zfyuer:0,
                money: {
                    xj: '',
                    zfbzh: '',
                    zfbzhje: '',
                    wxzh: '',
                    wxzhje: '',
                    yhzh: '',
                    yhzhje: ''
                },
                /*组件区域*/
                portComponents: {
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该班级, 是否继续?'
                        }
                    },
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的班级, 是否继续?'
                        }
                    },

                    course : {
                        type: 'course',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    article : {
                        type: 'article',
                        toggle: false,
                        params: '',
                        data: {}
                    },

                   xzwp : {
						type: 'xzwp',
						toggle: false,
						params: '',
						data: {}
					},
					ly: {
						type: 'ly',
						toggle: false,
						params: '',
						data: {}
					}
                },

                multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据

                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                    formatter: function (row, column) {}
                */
                portTitleList: [
                    {
                        prop:'id',
                        label:'id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    // {
                    //     prop:'type',
                    //     label:'商品类型',
                    //     hide:1,
                    //     align:'center',
                    //     fixed:false,
                    //     width:'',
                    //     minWidth:'',
                    //     headerAlign:'center',
                    //     formatter: function(row,column) {
                    //     }
                    // },
                    {
                        prop:'type',
                        label:'商品类型',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },{
                        prop:'mc',
                        label:'商品名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },
                    {
                        prop:'jcjg',
                        label:'基础价格',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },
                    {
                        prop:'jcjg',
                        label:'单价',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },
                    {
                        prop:'number',
                        label:'数量',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                    },{
                        prop:'dw',
                        label:'单位',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {
                            return row.type == "课程" ? '次数' :  '套'
                        }
                    },
                    // {
                    //     prop:'yhj',
                    //     label:'优惠金额（-）',
                    //     hide:1,
                    //     align:'center',
                    //     fixed:false,
                    //     width:'',
                    //     minWidth:'',
                    //     headerAlign:'center'
                    // },
                    {
                        prop:'zk',
                        label:'折扣',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {
                            return row.zk + "%"
                        }
                    }

                ],
                portBntList: [//接口按钮列表
                    {
                        name:'删除',
                        type:'singleDelete'
                    }
                ],

                /*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画

                /*模糊搜索条件*/
                inputbjmc:'' , //  班级名称,


                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [12, 24, 36, 72],//显示个数的选择器选项
                pagesize: 12,//每页显示条目数
                total: 0,//总条数


                dropDownData:'', //
            }
        },
        created () {
                // console.log(this.params)
            this.name = this.params.row.zwm;
            this.yuer = this.params.row.yuer;
            this.yzj = this.params.row.zj;
            this.yyhj = this.params.row.yhj;
            this.id = this.params.row.xsid;
            //加载页面时调用
            this.$store.dispatch('changeTitle','补交');//修改title
            this.$store.dispatch('changeRouterIndex','/cost/payjl');//修改路由
            this.search()
            this.isLoading = true;//动画开始
            this.yuer = this.params.row.yuer
            // alert(this.yuer)
        },
        mounted () {
            this.isLoading = false;//动画结束
        },
        methods: {

            tableRowClassName (row, index) {//隔行变色颜色设置
                /*if ( index%4 == 0) {
                    return "table-cell-green";
                }else if( index%4 == 1 ){
                    return "table-cell-yellow";
                }else if( index%4 == 2 ){
                    return "table-cell-red";
                }else{
                    return "table-cell-blue"
                }*/
            },

            zuofei(){
              this.$confirm('此操作将此订单作废, 是否继续?', '提示', {
      				 confirmButtonText: '确定',
      				 cancelButtonText: '取消',
      				 type: 'warning'
      			 }).then(() => {
               var logininfo = JSON.parse(localStorage.logininfo) ;
               var params3 = qs.stringify({
                   orderid: this.params.row.orderid,
                   xxid:logininfo.xxid,
                   yhid:logininfo.id,
    						});
               this.axios.post(this.$store.state.api + 'order/zf',params3)
               .then( res => {
               	     this.$message.success(res.data.msg);
                     this.$emit('close',{type:'renew',cancel:true})

                 }).catch( res => {
                     console.log(res)
                 })
      			 }).catch(() => {
      				 this.$message({
      					 type: 'info',
      					 message: '已取消'
      				 });
      			 });
            },
            submit () {
              var logininfo = JSON.parse(localStorage.logininfo) ;
              var params3 = qs.stringify({
                yc:this.yucun,
                zj:this.zj,
                yhj:this.yhj,
                jsr:logininfo.id,
                jfr:this.id,
                orderid: this.params.row.orderid,
                xj:this.money.xj,
                zfbzh:this.money.zfbzh,
                zfbje:this.money.zfbzhje,
                wxzh:this.money.wxzh,
                wxje:this.money.wxzhje,
                yhkzh:this.money.yhzh,
                yhkje:this.money.yhzhje,
                xxid:logininfo.xxid,
                yhid:logininfo.id,
                // je:this.amountReceived
                je:this.xfje,
                zfyuer:this.zfyuer,
                yhid:logininfo.id,
                xxid:logininfo.xxid
						});
              this.axios.post(this.$store.state.api + 'order/update',params3)
              .then( res => {
                    // resolve(res.data)
                    this.$emit('close',{type:'renew',cancel:true})

                }).catch( res => {
                })
            },
            tjxx(add){
                  // this.dataList.forEach( (v, i) => {
                  	
                  	var vsplxstr ="1";
                  	if (this.addlist[0].type == '物品' || this.addlist[0].type == '教材'){
                  		vsplxstr== '2'
                  	}
                  var params2 = qs.stringify({
                    orderid: this.params.row.orderid,
                    // this.addlist[0]
                    splx:  vsplxstr,
                    // splx: lx,
                    spid: this.addlist[0].id,
                    jg:this.addlist[0].jcjg,
                    zk: this.addlist[0].zk,
                    cns:this.addlist[0].number
      						});
                      this.axios.post(this.$store.state.api + 'ordermx/insert', params2)
                      .then( res => {
                          console.log(res)
                          console.log(111199999)
                      }).catch( res => {
                          console.log(res)
                      })


            },

            search () {
                // console.log(this.params.row.id )
              var logininfo = JSON.parse(localStorage.logininfo) ;
                var params3 = qs.stringify({
                	 yhid:logininfo.id,
                xxid:logininfo.xxid,
    							  orderid: this.params.row.orderid
    						});
                this.axios.post(this.$store.state.api + 'order/ordersp',params3)
                .then( res => {
                    console.log(res,11111111111)

                    // let list = res.data.data.list;
                    this.dataList = res.data.data.spmx;
                    this.info = res.data.data.info[0];
                    // this.total = data.totalPage;
                    // console.log(111)
                    // var arr = []
                    // list.forEach(v => {
                    //     if (v.splx) {
                    //         arr.push(v)
                    //     }
                    // })

                    // this.dataList = this.dataList.concat(arr);
                    this.amountReceived = this.dataList[0].je ?  this.dataList[0].je : this.amountReceived;



                    this.searchLoading = false;
                }).catch( res => {
                    console.log(res)
                    this.searchLoading = false;
                })
            },



            checkSelect (selection, row) {//点击单选select触发事件
                console.log(selection, row)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                // console.log(selection)
                let strID = [];

                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },


            cancel () {
               this.$emit('close',{type:'renew',cancel:true})
            },




            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        console.log(this.portComponents[i])

                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;

                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id

                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;

                        }else{
                            return;
                        }
                        return;
                    }
                }

            },
            componentsHide (setting) { //关闭组件
            	this.search ()
            	this.portComponents.ly.toggle = false
                if(setting.cancel != true){
                  this.addlist = setting.data
                  this.tjxx(this.addlist)
                }
            	
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;

                        if (!setting.cancel) {
                              this.search();
                            if (setting.type == "student") {
                                this.student = setting.data.zwm + ' - ' + setting.data.xh
                            }else{
                                setting.data.forEach( (v) => {
                                   this.dataList.push(v)
                                })

                            }
                        }
                        return;
                    }
                }
            }

        },
        watch:{
            'zfyuer': function(newVal,oldVal){
                if(parseInt(newVal)>=parseInt(this.yuer)) {//如果小于等于零
                    this.zfyuer = this.yuer //恢复原值
                }
                if(parseInt(this.zfyuer)>=parseInt(this.xujiao)){
                  this.zfyuer = this.xujiao
                }

            }
        },
        computed: {
          yjje1 () { //应交金额
              let number = 0.00;
              number += this.xujiao - this.zj - this.zfyuer -this.yhj
              if(number>=0){
                return number
              }else{
                return 0
              }
          },
          sum () {
              // return this.money.xj*1 + this.money.zfbzhje*1 + this.money.wxzhje*1 + this.money.yhzhje*1 + this.zfyuer*1
              return this.money.xj*1 + this.money.zfbzhje*1 + this.money.wxzhje*1 + this.money.yhzhje*1
          },
          yucun(){
            if(this.sum - this.yjje1>=0){

              return this.sum - this.yjje1
            }else{
              return 0
            }
          },
          qf1(){
            let number = this.yjje1-this.sum
            if(number<=0){
              return 0
            }else{
              return number.toFixed(2)
            }
          //
          },
            sjyuer(){
              let number = this.yuer - this.zfyuer;
              if (number<=0) {
                return 0.00
              }
              return number
            },
            goodsTotal () { //物品合计
                let number = 0.00;
                for (let i in this.dataList) {
                    if (this.dataList[i].type == '物品' ||  this.dataList[i].type == '教材'   ) {
                        // console.log(this.dataList[i])
                        number += (this.dataList[i].jcjg || 0) * (this.dataList[i].number || 0) * (this.dataList[i].zk.replace(/%/,"")*1/100 || 0);
                        // number += (this.dataList[i].jcjg || 0) * (this.dataList[i].number || 0) * (this.dataList[i].zk.replace(/%/,"")*1/100 || 0)
                    }
                }
                return number
            },
            courseTotal () { //课时合计
                let number = 0.00;
                for (let i in this.dataList) {
                    if (this.dataList[i].type == '课程') {
                        // number += (this.dataList[i].jg || 0)*1;
                        // console.log(122)
                        //
                        // console.log(this.dataList[i].jg,this.dataList[i].cns,this.dataList[i].zk.replace(/%/,"")*1/100)
                        // number += (this.dataList[i].jg || 0) * (this.dataList[i].cns || 0) * (this.dataList[i].zk.replace(/%/,"")*1/100 || 0)
                        number += (this.dataList[i].jcjg || 0) * (this.dataList[i].number || 0) * (this.dataList[i].zk.replace(/%/,"")*1/100 || 0)
                          console.log(number)
                    }
                }
                return number
            },
            totalAmount () {

                return this.goodsTotal + this.courseTotal;
            },
            xujiao () {

                return this.goodsTotal + this.courseTotal-this.amountReceived;
            },
            xfje(){

                return this.money.xj + this.money.zfbzhje + this.money.wxzhje + this.money.yhzhje
            },
            // sum () {
            //     return this.money.xj*1 + this.money.zfbzhje*1 + this.money.wxzhje*1 + this.money.yhzhje*1
            // },
            accountDisabled () {
                return this.dataList.length > 0 && this.studentid ? false : true
            }
        }
    }
</script>

<style lang="less" scoped>
    .index-page {
        font-size:12px;
        position: absolute;
        background: #E8EDF0;
        width: 100%;
        height: 100%;
        top: 0;
        z-index: 10;
        .admin-table {
            margin-top:10px;
        }
         .but1{
			width: 100%;
		}
		.code-search {
            height: 30px;
            margin:10px 0 10px 0;
            min-width: 100px;
			max-width: 135px;
        }
        .btn {
			 height: 30px;
            padding:0 10px;
            margin-top: 8px;
		}
        .name {
          margin-top: 20px;
            .student1{
                width:150px;
            }
        }

        .state {
            width:100%;
            margin-top:20px;
            text-align: center;

            .left,.right {
                float: left;
                width: 50%;
            }

            h3 {
                // width: 350px;
                text-align: center;
                color:#333;
            }
            .item {
                width: 350px;
                margin:10px 0;
            }

            .amount {
                font-size:30px;
                margin-top:20px;
            }

            .left span{
                display: inline-block;
                width:100px;
                text-align: right;
            }
            .right {
                text-align: left;
            }

            .right .item {
                width:500px;

                .title {
                    width: 300px;
                }

                .content {
                    width:150px;
                }
            }
            .right .xj {
                width:400px;
            }
        }

        .content-input {
            height:20px;
        }

        .submit {
            width:120px;
            // display: block;
            margin-left: 25%;
            margin-bottom: 100px;
        }
        .submit2 {
            width:120px;
            margin-left:50px;
        }
        .submit3 {
            width:120px;
            margin-left:50px;
        }

        .item-input {
            width: 200px;
        }

        .total {
            text-align: right;
            margin:10px 0;
            span{
                margin:0 10px;
            }
        }

        article {
            margin:15px 0;
            margin-top:0px;

            p{
                background: #fcf4eb;
                padding:10px 5px;
            }
            input {
                border:none;
                outline: none;
                background: transparent;
                border-bottom:1px solid #ccc;
            }
            div {
                background: rgba(252,244,235,0.7);
                padding:10px 5px;
            }
            .space-between {
                padding:10px 0;
                display: block;
            }
        }

        .settlement {
            p{
                background: #fcf4eb;
            }
            div {
                background: rgba(252,244,235,0.7);
            }
        }

        .receiving-account {
            p{
                background: #F1FDFC;
            }
            div {
                background: rgba(241,253,252,0.7);
            }
        }

        .other-information {
            p{
                background: #e5e9f2;
            }
            div {
                background: rgba(229,233,242,0.7);
            }
        }
    }
</style>
